import { Upload } from "@/api/interface/index";
import { PORT1 } from "@/api/config/servicePort";
import http from "@/api";

/**
 * @name 文件上传模块
 */
// 图片上传
export const uploadImg = (params: FormData) => {
  return http.post<Upload.ResFileUrl>(PORT1 + `/file/upload/img`, params, { cancel: false });
};

// 视频上传
export const uploadVideo = (params: FormData) => {
  return http.post<Upload.ResFileUrl>(PORT1 + `/file/upload/video`, params, { cancel: false });
};

// PDF上传
export const uploadFile = (params: any) => {
  return http.post(PORT1 + `/upload/file`, params, { cancel: false });
};

/**
 * @name 替换文件
 */
export const ReplaceFile = (params: any) => {
  return http.post(PORT1 + `/upload/repalce`, params, { loading: true });
};

/**
 * @name 文件下载模块
 */

// 通用文件下载
export const DownloadFile = (params: any) => {
  return http.download(PORT1 + `/download/file`, params, { loading: false });
};

/**
 * @name 获取文件信息
 */

// 获取文件目录结构
export const GetPDFFolder = (params: any) => {
  return http.post(PORT1 + `/getFileInfo/get_folder`, params, { loading: true });
};

// 获取文件目录结构
export const GetFolder = (params: any) => {
  return http.post(PORT1 + `/getFileInfo/get_folder_tree`, params, { loading: true });
};

// 获取IMAGE数据
export const GetIMAGE = (params: any) => {
  return http.post(PORT1 + `/getFileInfo/get_image_file`, params, { loading: true, responseType: "blob" });
};

// 获取IMAGE tab数据
export const GetIMAGETab = (params: any) => {
  return http.post(PORT1 + `/getFileInfo/get_image_tab`, params, { loading: true });
};

/**
 * @name 删除文件
 */
export const DeleteFile = (params: any) => {
  return http.post(PORT1 + `/delete/file`, params, { loading: true });
};

/**
 * @name 修改文件
 */
export const GetLink = (params: any) => {
  return http.post(PORT1 + `/change/get_link`, params, { loading: true });
};

export const saveLink = (params: any) => {
  return http.post(PORT1 + `/change/save_link`, params, { loading: true });
};

export const saveAllLinks = (params: any) => {
  return http.post(PORT1 + `/change/save_all_links`, params, { loading: true });
};

export const GetFileData = () => {
  return http.get(PORT1 + `/change/filedata`, {}, { loading: true });
};

export const GetTabData = (params: any) => {
  return http.post(PORT1 + `/change/get_tab`, params, { loading: true });
};

export const addTabData = (params: any) => {
  return http.post(PORT1 + `/change/add_tab`, params, { loading: true });
};

export const deleteTabData = (params: any) => {
  return http.post(PORT1 + `/change/del_tab`, params, { loading: true });
};
